﻿using System;
using System.IO;
using System.IO.Pipes;

class PipeClient
{
    static void Main(string[] args)
    {
        if (args.Length > 0)
        {
            PipeStream pipeClientIn = new AnonymousPipeClientStream(PipeDirection.In, args[0]);
            PipeStream pipeClientOut = new AnonymousPipeClientStream(PipeDirection.Out, args[1]);

            StreamReader clientSideStreamReader = new StreamReader(pipeClientIn);
            StreamWriter clientSideStreamWriter = new StreamWriter(pipeClientOut);
            
            
            using (pipeClientIn)
            {
                using (clientSideStreamReader)
                {
                    // Display the read text to the console
                    string temp;
                    while ((temp = clientSideStreamReader.ReadLine()) != null)
                    {
                        Console.WriteLine("Client says: ");
                    }


                }
            }






            try
            {
                // Read user input and send that to the server process.
                using (clientSideStreamWriter)
                {
                    clientSideStreamWriter.AutoFlush = true;
                    Console.Write("Client Says: ");
                    clientSideStreamWriter.WriteLine(Console.ReadLine());
                }
            }
            // Catch the IOException that is raised if the pipe is broken
            // or disconnected.
            catch (IOException e)
            {
                Console.WriteLine("ERROR: {0}", e.Message);
            }







        }
        //Console.Write("Client Press Enter to continue...");
        //Console.ReadLine();
    }
}
